package cn.itcast.bos.commons;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.Map;

import org.springframework.data.domain.Page;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

import cn.itcast.bos.domain.base.Area;

public abstract class BaseAction<T> extends ActionSupport implements ModelDriven<T>{
	
	protected T model;
	@Override
	public T getModel() {
		return model;
	}
	public BaseAction() {
		Type genericSuperclass = this.getClass().getGenericSuperclass();
		ParameterizedType parameterizedType=(ParameterizedType)genericSuperclass;
		Class<T> modelClass  = (Class<T>) parameterizedType.getActualTypeArguments()[0];
		
		try {
			model = modelClass.newInstance();
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("模型构造失败");
		} 
		
	}
	
	protected Integer page;
	protected Integer rows;
	
	public void setPage(Integer page) {
		this.page = page;
	}

	public void setRows(Integer rows) {
		this.rows = rows;
	}
	
	
	protected void pushValueStack(Page<T> pagedata){
		
		
		Map<String, Object> map=new HashMap<String, Object>();
		map.put("total", pagedata.getTotalElements());
		map.put("rows", pagedata.getContent());
		
		ActionContext.getContext().getValueStack().push(map);
		
		
		
		
	}
	
	
	

}
